package com.bjtu.toyexchange;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class GalleryAdapter extends BaseAdapter{
	private Context context;
	private int[] data;
	//构造函数
	public GalleryAdapter(Context context,int[] data) {
		this.context=context;
		this.data=data;
	}
	public int getCount() {
		return data.length;
	}
	public Object getItem(int position) {
		return data[position%data.length];
	}
	public long getItemId(int position) {
		return position%data.length;
	}
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView iv=new ImageView(context);
		iv.setLayoutParams(new Gallery.LayoutParams(100, 100));
		iv.setImageResource(data[position%data.length]);
		iv.setScaleType(ScaleType.FIT_CENTER);
		return iv;
	}

}
